package com.dog.basics.admin.controller.common;

import com.dog.basics.bean.dto.admin.common.NettyTreatyAdminDto;
import com.dog.basics.common.constant.SwaggerConstants;
import com.dog.basics.common.util.R;
import com.dog.basics.service.common.NettyTreatyService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

/**
 * @description: 协议控制层
 * @author: He
 * @date: Created in 2020/10/14 10:05
 * @version: 1.0
 * @modified By:
 */
@RestController
@RequestMapping("/admin/treaty")
@AllArgsConstructor
@Api(value = "指令控制", tags = SwaggerConstants.COMMON + "指令控制")
public class NettyTreatyController {

    private final NettyTreatyService treatyService;


    /**
     * @功能描述: 公共协议远程控制指令
     * @author He
     * @date 2020/10/14
     */
    @PostMapping("/send/instructions")
    @PreAuthorize("@pms.hasPermission('treaty:send:instructions')")
    @ApiOperation(value = "远程控制指令", notes = "远程控制指令 [5-远程在线升级 6-远程重启 7-远程关机 8-远程自定义控制] 权限标识:(treaty:send:instructions)")
    public R<Boolean> sendTreatyInstructions(@RequestBody NettyTreatyAdminDto dto) {
        return R.ok(treatyService.sendTreatyInstructions(dto));
    }

    /**
     * @功能描述: 公共协议远程控制指令-硬件是否执行成功
     * @author He
     * @date 2020/10/14
     */
    @GetMapping("/send/instructions")
    @PreAuthorize("@pms.hasPermission('treaty:get:instructions')")
    @ApiOperation(value = "查询远程控制指令", notes = "查询远程控制指令是否控制成功 (轮训30秒如果未得到答应,就是超时) 权限标识: (treaty:get:instructions)")
    public R<Boolean> sendTreatyInstructionsIsSuccess(NettyTreatyAdminDto dto) {
        return R.ok(treatyService.sendTreatyInstructionsIsSuccess(dto));
    }



}